<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('发送邮件')" />
    <th:block th:include="include :: summernote-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-mail-send">
        <input name="uuid" th:value="*{uuid}" type="hidden">
        <input name="files" id="files" type="hidden">
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label">发送人账号：</label>
                    <div class="col-sm-8">
                        <input name="mailTo" class="form-control" type="text" value="360628455@qq.com" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label">邮件主题：</label>
                    <div class="col-sm-8">
                        <input name="subject" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row ">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label">邮件内容：</label>
                    <div class="col-sm-8 hidden">
                        <textarea type="text" name="context" class="form-control" placeholder="请输入文本" id = "context"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <div class="row">
        <div class="col-sm-12">
            <div class="form-group">
            <div class="ibox float-e-margins" style="margin:0 auto;width:75%;">
                <div class="ibox-title">
                    <button id="edit" class="btn btn-primary btn-xs m-l-sm" onclick="edit()" type="button">编辑</button>
                    <button id="save" class="btn btn-primary  btn-xs" onclick="save()" type="button">保存</button>
                </div>
                <div class="ibox-content" id="eg">
                    <div class="click2edit wrapper">
                    </div>
                </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>附件上传</h5>
                </div>
                <div class="ibox-content">
                    <div class="form-group">
                        <label class="font-noraml">多文件上传</label>
                        <div class="file-loading">
                            <input id="fileinput-demo-1" name="file" type="file" multiple>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: summernote-js" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<script type="text/javascript">
    var prefix = ctx + "mail"
    $("#form-mail-send").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
           save();
           var files = "";
            $(".file-preview-success").each(function (key,value) {
                if(key == 0){
                    files += $(this).attr("fileid");
                }else{
                    files += (","+$(this).attr("fileid"));
                }

            })
            if(files!="") {
                $("#files").prop("value", files)
            }
            $.operate.save(prefix + "/send", $('#form-mail-send').serialize());
        }
    }

    $(document).ready(function () {
        $('.summernote').summernote({
            lang: 'zh-CN'
        });
    });
    var edit = function () {
        $("#eg").addClass("no-padding");
        $('.click2edit').summernote({
            lang: 'zh-CN',
            focus: true
        });
    };
    var save = function () {
        $("#eg").removeClass("no-padding");
        var aHTML = $('.click2edit').summernote('code');
        $('#context').text(aHTML)
        $('.click2edit').summernote('destroy');
    };

    $(document).ready(function () {
        $("#fileinput-demo-1").fileinput({
            language:'zh',
            theme: 'grid',
            uploadUrl: '/ftp/upload',
            uploadExtraData:{ "bizeType": '邮件' },
            maxFileCount:1,//允许同时上传的最大文件数
            enctype:'multipart/form-data',
            validateInitialCount:true,
        }).on("fileuploaded", function (event, data, previewId, index) {
            $('#' + previewId).attr('fileid', data.response.fileInfoId);
           // self._errorHandler(event,previewId);
        }).on('fileerror', function(event, data, msg) {  //一个文件上传失败
            alert("失败");

        })
    });

</script>
</body>
</html>